package com.zagj.videocomparess;

import android.app.Activity;
import android.content.Intent;
import android.os.Environment;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.zagj.videocomparess.encode.AudioEncoder;
import com.zagj.videocomparess.utils.AudioPlayer;

import java.io.File;
import java.io.IOException;

public class MainActivity extends Activity implements View.OnClickListener {
public  String video_path= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()+ File.separator+"test.ts";
public  String pic_path= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()+File.separator+"1.jpg";
public  String sava_path= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()+File.separator+"2.flv";
public  String music_path= Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath()+File.separator+"hello1.mp4";
    private Button mViewById;
    private Button mViewById1;
    private Button mViewById2;
    private Button mViewById3;
    private Button mViewById4;
    private AudioEncoder audioEncoder;
    private Button mViewById5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mViewById1 = (Button) findViewById(R.id.button1);
        mViewById2 = (Button) findViewById(R.id.button2);
        mViewById3 = (Button) findViewById(R.id.button3);
        mViewById4 = (Button) findViewById(R.id.button4);
        mViewById5 = (Button) findViewById(R.id.button5);

        mViewById1.setOnClickListener(this);
        mViewById2.setOnClickListener(this);
        mViewById3.setOnClickListener(this);
        mViewById4.setOnClickListener(this);
        mViewById5.setOnClickListener(this);
    }
    public native int addFilter(String  videoPath,String  picturePath, String savaPath);
    public native int voiceFilter(String  videoPath,String  picturePath);
    public native int cutFilter(String  videoPath,String  picturePath);
    static{
        System.loadLibrary("x2641");
        System.loadLibrary("avutil-55");
        System.loadLibrary("swresample-2");
        System.loadLibrary("avcodec-57");
        System.loadLibrary("avformat-57");
        System.loadLibrary("swscale-4");
        System.loadLibrary("avfilter-6");
        System.loadLibrary("postproc-54");
        System.loadLibrary("avdevice-57");
        System.loadLibrary("sffcompare");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.button1:
                int ret=addFilter(video_path,pic_path,sava_path);
                Log.e("onClick: ", "onClick: "+ret );
                break;
            case R.id.button2:
                Intent intent=new Intent(this,MediaRetrieverActivity.class);
                startActivity(intent);
                break;
            case R.id.button3:
                Intent intentAudio=new Intent(this,AudioRetrieverActivity.class);
                startActivity(intentAudio);

              /*  audioEncoder = new AudioEncoder();
                try {
                    audioEncoder.prepare();
                    audioEncoder.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }*/

                break;
            case R.id.button4:
                Intent intentPlayer=new Intent(this,CameraVideoActivity.class);
                intentPlayer.putExtra("meidaType","play");
                startActivity(intentPlayer);
                break;
            case R.id.button5:
                //audioEncoder.stop();
                Intent intentMediaLive=new Intent(this,CameraVideoActivity.class);
                startActivity(intentMediaLive);
                break;
        }
    }
}
